<template>
  <el-row
    type="flex"
    justify="space-around"
    style="height: 40px; width: 100%"
    align="middle"
  >
    <!-- 左边 -->
    <el-col>{{ treeData.name }}</el-col>
    <!-- 右边 -->
    <el-col>
      <el-row type="flex" justify="end">
        <el-col :span="6">{{ treeData.manager }}</el-col>
        <el-col :span="6">
          <!-- 下拉菜单 -->
          <el-dropdown>
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="$emit('addDept', treeData.id)">
                添加子部门
              </el-dropdown-item>
              <el-dropdown-item
                v-if="!isRoot"
                @click.native="$emit('editDept', treeData.id)"
              >
                编辑部门
              </el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="delRow">
                删除部门
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
import { delDepartmentApi } from "@/api/department";
export default {
  name: "TreeTools",
  props: {
    // 是否根节点
    isRoot: {
      type: Boolean,
      default: false,
    },
    // 工具条的数据
    treeData: {
      type: Object, // { name:'xxx', magager:'xx' }
      required: true,
    },
  },
  methods: {
    // 删除当前行的数据
    async delRow() {
      // 1.提示确认框
      try {
        await this.$confirm("确认删除吗？");
      } catch (error) {
        return console.log(error);
      }
      // 2. 发生删除请求
      await delDepartmentApi(this.treeData.id);
      // 3. 失败处理
      // 4. 成功处理
      this.$message.success("删除成功");
      this.$emit("updateList");
    },
  },
};
</script>
<style></style>
